﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CuoiHoi.Business;
using CuoiHoi.Entities;

namespace CuoiHoi.Admin
{
    public partial class ucTinTuc : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            loadTheLoai();
        }

        void loadTheLoai()
        {
            cbbTheLoai.DataSource = BTheLoai.SelectAll();
            cbbTheLoai.DataTextField = "TenTheLoai";
            cbbTheLoai.DataValueField = "idTheLoai";
            cbbTheLoai.DataBind();
        }

        void ThongBao(string Loi)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Thông báo!", "<script>alert('" + Loi + "')</script>", false);
        }

        protected void btnThem_Click1(object sender, EventArgs e)
        {
            string path = "",filename="";
            if (FileUpload1.HasFile)
            {
                filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + FileUpload1.FileName;
                path = Server.MapPath("~/images/" + filename);
                FileUpload1.SaveAs(path);
            }


            BTinTuc.Insert(new ETinTuc
            {
                AnhDaiDien = filename,
                idNhanVien = 1,
                idTheLoai = int.Parse(cbbTheLoai.SelectedValue),
                MoTa = txtMoTa.Value,
                NgayDang = DateTime.Now,
                NoiDung = txtNoiDung.Text,
                TieuDe = txtTieuDe.Value
            });

            Session["action"] = 1;
            Response.Redirect("~/Admin/Default.aspx?idpage=qltt");
        }


    }
}